using System;
using System.Collections.Generic;
using UnityEngine;

public class MatchUI : MonoBehaviour
{
	public List<UILabel> debugLabels = new List<UILabel>();

	public List<PointsLabel> pointsLabels = new List<PointsLabel>();

	public UIPanel uiRoot;

	public GameObject singlePlayerUI;

	public Arrow arrow;

	public GameObject marker;

	public TextMessagesDisplay textMessagesDisplay;

	public QualityLabel qualityLabel;

	public CameraButton cameraButton;

	public RacketButton racketButton;

	public AiTestButton aiTestButton;

	public TrailRenderer fingerTrailRanderer;

	public ThumbController thumbController;

	public QualityDisplay qualityDisplay;

	public ServeDisplay serveDisplay;

	public AreaMarker areaMarker;

	public BallMarker ballMarker;

	public PositionFollower ballFollower;

	public MessageBubble msgBubble;

	public ScoreDialog scoreDialog;

	public GameObject pauseButton;

	public List<UIPlayerScoreBoard> scoreBoards = new List<UIPlayerScoreBoard>();

	public MultiplayerGameDone gameDone;

	public Transform markerSphere;

	public WinDialogUI winDialog;

	public GameObject opponentMessageButton;

	public MessageDisplay rematchPlayerBubble;

	public MessageDisplay rematchOpponentBubble;

	public MessageMenu msgMenu;

	private bool msgMenuOpen;

	protected MatchControllerUiInteface match;

	public ElementHighlighter highlighter;

	public Action onStartServer;

	public Action onStopServer;

	public DisconnectLabel disconnectLabel;

	public UIHand swipePointer;

	public TabletopHighlight tabletopHighlight;

	public MessageBubble instructionsBubble;

	public MessageBubble timingHighlight;

	public IntroLayer intro;

	public GameObject pauseTimeButton;

	public GameObject cameraChangeButton;

	public HitsDisplay hitsDisplay;

	public CareerWinDialog careerWinDialog;

	public ConnectionSpeedIndicatorController connectionSpeedDisplay;

	public StatsDisplay statsDisplay;

	private void OnEnable()
	{
		if (MatchParameters.InitParameters.matchType == MatchType.MultiPlayer)
		{
			msgMenuOpen = false;
			opponentMessageButton.SetActive(false);
			MatchParameters.MatchParams initParameters = MatchParameters.InitParameters;
			scoreBoards[0].ShowStar(GGPlayerSettings.instance.Level());
			scoreBoards[1].ShowStar(initParameters.multiplayerParams.opponentLevel);
			if (connectionSpeedDisplay != null)
			{
				connectionSpeedDisplay.gameObject.SetActive(true);
			}
			return;
		}
		if (connectionSpeedDisplay != null)
		{
			connectionSpeedDisplay.gameObject.SetActive(false);
		}
		UITools.SetActive(opponentMessageButton, false);
		foreach (UIPlayerScoreBoard scoreBoard in scoreBoards)
		{
			if (scoreBoard != null)
			{
				scoreBoard.HideStar();
			}
		}
	}

	public PointsLabel GetPointsLabel(TableTennisPlayerBase player)
	{
		if (pointsLabels.Count == 0)
		{
			return null;
		}
		return pointsLabels[player.teamTag % pointsLabels.Count];
	}

	public void StartServer()
	{
		if (onStartServer != null)
		{
			onStartServer();
		}
	}

	public void StopServer()
	{
		if (onStopServer != null)
		{
			onStopServer();
		}
	}

	public void Init(MatchControllerUiInteface match, PhysicsBall ball)
	{
		this.match = match;
		if (scoreBoards[0] != null)
		{
			scoreBoards[0].SetScore(0.ToString());
			string profileUrl = ((MatchParameters.InitParameters.matchType != MatchType.MultiPlayer || !GGPlayerSettings.instance.useProfilePictureInMultiplayer || BehaviourSingletonInit<FriendProfilesManager>.instance.myProfile == null) ? string.Empty : BehaviourSingletonInit<FriendProfilesManager>.instance.myProfile.pictureUrl);
			scoreBoards[0].SetNameFlagAndProfilePicture(MatchParameters.InitParameters.player1Name, MatchParameters.InitParameters.player1Flag, profileUrl, true);
		}
		if (scoreBoards[1] != null)
		{
			scoreBoards[1].gameObject.SetActive(true);
			string profileUrl2 = ((MatchParameters.InitParameters.matchType != MatchType.MultiPlayer || !GGPlayerSettings.instance.useProfilePictureInMultiplayer) ? string.Empty : MatchParameters.InitParameters.multiplayerParams.opponentImageUrl);
			scoreBoards[1].SetNameFlagAndProfilePicture(MatchParameters.InitParameters.player2Name, MatchParameters.InitParameters.player2Flag, profileUrl2, false);
			scoreBoards[1].SetScore(0.ToString());
		}
		ballFollower.Init(ball);
	}

	public void SetScores(int player, string score)
	{
		scoreBoards[player].SetScore(score);
	}

	public void SetServeTime(TableTennisPlayerBase player, float time, float totalTime)
	{
		for (int i = 0; i < scoreBoards.Count; i++)
		{
			UIPlayerScoreBoard uIPlayerScoreBoard = scoreBoards[i];
			if (i == player.teamTag)
			{
				uIPlayerScoreBoard.SetTime(time, totalTime);
			}
			else
			{
				uIPlayerScoreBoard.HideTime();
			}
		}
	}

	public void HideServeTime()
	{
		foreach (UIPlayerScoreBoard scoreBoard in scoreBoards)
		{
			scoreBoard.HideTime();
		}
	}

	public void SetPauseActive(bool active)
	{
		UITools.SetActive(pauseButton, active);
	}

	private void Update()
	{
		bool flag = match != null && match.isGameWon();
		bool flag2 = match != null && match.GetGameType().canPause;
		bool flag3 = pauseButton != null && pauseButton.activeSelf;
		if (NavigationManager.instance.shouldGoBack && flag3 && !flag && flag2)
		{
			if (!msgMenuOpen)
			{
				GGDebug.DebugLog("Show pause menu");
				showPauseMenu();
			}
			else
			{
				GGDebug.DebugLog("Hide pause menu");
				OnPauseMenu(true);
			}
		}
	}

	public void showPauseMenu()
	{
		match.OnPause();
	}

	public void ShowPauseDialog(string title, string text, string yes, string no)
	{
		msgMenuOpen = true;
		UIDialog.instance.ShowYesNo(title, text, yes, no, OnPauseMenu);
	}

	private void OnPauseMenu(bool success)
	{
		NavigationManager.instance.Pop(true);
		bool exit = !success;
		msgMenuOpen = false;
		match.OnResume(exit);
	}

	public void MessageFromOpponent(string msg)
	{
		scoreBoards[1].messageDisplay.TweenMessage(msg);
	}

	public void MessageToOpponent(string msg)
	{
		Analytics.instance.ReportMessageSent(msg, false);
		scoreBoards[0].messageDisplay.TweenMessage(msg);
	}

	public void RematchMessageFromOpponent(string msg)
	{
		rematchOpponentBubble.TweenMessage(msg);
	}

	public void RematchMessageToOpponent(string msg)
	{
		Analytics.instance.ReportMessageSent(msg, true);
		rematchPlayerBubble.TweenMessage(msg);
	}

	public void UpdateRematchButton(RematchStatus status)
	{
		gameDone.UpdateButtons(status);
	}

	public void DisableRematchButtons()
	{
		gameDone.DisableButtons();
	}

	public void DisableRematchOnly()
	{
		gameDone.DisableRematchOnly();
	}

	public void RematchSent()
	{
		gameDone.RematchSent();
	}

	public void OnMessagesOpen()
	{
		msgMenuOpen = true;
		msgMenu.OnOpen();
	}

	public void OnSendMessage(string message)
	{
		match.OnSendMessage(message);
		OnMessagesClosed();
	}

	public void OnMessagesClosed()
	{
		msgMenuOpen = false;
		NavigationManager.instance.Pop();
		msgMenu.OnClose();
	}

	public void UpdateSets(int player, int opponent)
	{
		scoreBoards[0].SetSets(player);
		scoreBoards[1].SetSets(opponent);
	}

	public void OnRematchClick()
	{
		match.OnRematch();
	}
}
